<template>
    <div>
      <h1>病房信息列表</h1>
      <a href="/AddRoomView">病房信息添加</a>
      <br>
      <a href="/AddClassView">科室信息添加</a>
      <br>
      病房名称：<input type="text" v-model="find.name">
      科室名称：   <select v-model="find.cid">
                        <option value="0">请选择</option>
                        <option v-for="a in swert"  :value="a.cid">{{ a.name }}</option>
                    </select>
      <input type="button" value="查询" @click="Show">
      <table class="table">
        <thead>
            <tr>
                <td>病房号</td>
                <td>病房名称</td>
                <td>所属科室</td>
                <td>床位总数量</td>
                <td>默认状态</td>
                <td>状态</td>
                <td>空闲床数量</td>
                <td>创建日期</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="a in data">
                <td>{{ a.rid }}</td>
                <td>{{ a.name }}</td>
                <td>{{ a.cname }}</td>
                <td>{{ a.num }}</td>
                <td>{{ a.mstart?"未满":"已满" }}</td>
                <td>{{ a.start?"维修":"启用" }}</td>
                <td>{{a.knum  }}</td>
                <td>{{ moment(a.createTime).format("YYYY-MM-DD") }}</td>
                <td><input type="button" :value='a.start?"启用":"维修"' @click="UptStart(a.id)"></td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import moment from "moment";
const data=ref([{
   "rid": "1001",
    "name": "内科病房",
    "cid": 1,
    "createTime": "2025-05-15T00:00:00",
    "num": 5,
    "mstart": true,
    "start": true,
    "knum": 3,
    "id": 2,
    "cname": "内科"
}])
onMounted(()=>{
    Show()
    Xiala()
})
const Show=()=>{
    axios.get("https://localhost:7140/api/Room/GetRoom",{params:find.value}).then(res=>{
        data.value=res.data
    })
}
const find=ref({
    name:"",
    cid:0
})
const swert=ref([{
    "cid": 1,
    "name": "内科",
}])
const Xiala=()=>{
    axios.get("https://localhost:7140/api/Room/Xiala").then(res=>{
        swert.value=res.data
    })
}
const UptStart=(id:any)=>{
    if(!confirm("确认修改吗")){
        return;
    }
    axios.get("https://localhost:7140/api/Room/UptStart",{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert('修改成功');
            Show();
        }
        else{
            alert('修改失败');
        }
    })
}
</script>

<style scoped>

</style>